home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / samba.idb / usr / samba / src / source / chgpasswd.c.z / chgpasswd.c
Encoding:
C/C++ Source or Header  |  1998-10-28  |  17.6 KB  |  670 lines

  1. /* 
  2.    Unix SMB/Netbios implementation.
  3.    Version 1.9.
  4.    Samba utility functions
  5.    Copyright (C) Andrew Tridgell 1992-1998
  6.    
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 2 of the License, or
  10.    (at your option) any later version.
  11.    
  12.    This program is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.    
  17.    You should have received a copy of the GNU General Public License
  18.    along with this program; if not, write to the Free Software
  19.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. /* fork a child process to exec passwd and write to its
  23. * tty to change a users password. This is running as the
  24. * user who is attempting to change the password.
  25. */
  26.  
  27. /* 
  28.  * This code was copied/borrowed and stolen from various sources.
  29.  * The primary source was the poppasswd.c from the authors of POPMail. This software
  30.  * was included as a client to change passwords using the 'passwd' program
  31.  * on the remote machine.
  32.  *
  33.  * This routine is called by set_user_password() in password.c only if ALLOW_PASSWORD_CHANGE
  34.  * is defined in the compiler directives located in the Makefile.
  35.  *
  36.  * This code has been hacked by Bob Nance (nance@niehs.nih.gov) and Evan Patterson
  37.  * (patters2@niehs.nih.gov) at the National Institute of Environmental Health Sciences
  38.  * and rights to modify, distribute or incorporate this change to the CAP suite or
  39.  * using it for any other reason are granted, so long as this disclaimer is left intact.
  40.  */
  41.  
  42. /*
  43.    This code was hacked considerably for inclusion in Samba, primarily
  44.    by Andrew.Tridgell@anu.edu.au. The biggest change was the addition
  45.    of the "password chat" option, which allows the easy runtime
  46.    specification of the expected sequence of events to change a
  47.    password.
  48.    */
  49.  
  50. #include "includes.h"
  51.  
  52. extern int DEBUGLEVEL;
  53.  
  54. #ifdef ALLOW_CHANGE_PASSWORD
  55.  
  56. #define MINPASSWDLENGTH 5
  57. #define BUFSIZE 512
  58.  
  59. static int findpty(char **slave)
  60. {
  61.   int master;
  62. #if defined(SVR4) || defined(SUNOS5)
  63.   extern char *ptsname();
  64. #else /* defined(SVR4) || defined(SUNOS5) */
  65.   static char line[12];
  66.   void *dirp;
  67.   char *dpname;
  68. #endif /* defined(SVR4) || defined(SUNOS5) */
  69.   
  70. #if defined(SVR4) || defined(SUNOS5)
  71.   if ((master = open("/dev/ptmx", O_RDWR)) >= 1) {
  72.     grantpt(master);
  73.     unlockpt(master);
  74.     *slave = ptsname(master);
  75.     return (master);
  76.   }
  77. #else /* defined(SVR4) || defined(SUNOS5) */
  78.   safe_strcpy( line, "/dev/ptyXX", sizeof(line)-1 );
  79.  
  80.   dirp = OpenDir(-1, "/dev", False);
  81.   if (!dirp) return(-1);
  82.   while ((dpname = ReadDirName(dirp)) != NULL) {
  83.     if (strncmp(dpname, "pty", 3) == 0 && strlen(dpname) == 5) {
  84.       DEBUG(3,("pty: try to open %s, line was %s\n", dpname, line ) );
  85.       line[8] = dpname[3];
  86.       line[9] = dpname[4];
  87.       if ((master = open(line, O_RDWR)) >= 0) {
  88.         DEBUG(3,("pty: opened %s\n", line ) );
  89.     line[5] = 't';
  90.     *slave = line;
  91.     CloseDir(dirp);
  92.     return (master);
  93.       }
  94.     }
  95.   }
  96.   CloseDir(dirp);
  97. #endif /* defined(SVR4) || defined(SUNOS5) */
  98.   return (-1);
  99. }
  100.  
  101. static int dochild(int master,char *slavedev, char *name, char *passwordprogram, BOOL as_root)
  102. {
  103.   int slave;
  104.   struct termios stermios;
  105.   struct passwd *pass = Get_Pwnam(name,True);
  106.   int gid;
  107.   int uid;
  108.  
  109.   if(pass == NULL) {
  110.     DEBUG(0,("dochild: user name %s doesn't exist in the UNIX password database.\n",
  111.               name));
  112.     return False;
  113.   }
  114.  
  115.   gid = pass->pw_gid;
  116.   uid = pass->pw_uid;
  117. #ifdef USE_SETRES
  118.   setresuid(0,0,0);
  119. #else /* USE_SETRES */
  120.   setuid(0);
  121. #endif /* USE_SETRES */
  122.  
  123.   /* Start new session - gets rid of controlling terminal. */
  124.   if (setsid() < 0) {
  125.     DEBUG(3,("Weirdness, couldn't let go of controlling terminal\n"));
  126.     return(False);
  127.   }
  128.  
  129.   /* Open slave pty and acquire as new controlling terminal. */
  130.   if ((slave = open(slavedev, O_RDWR)) < 0) {
  131.     DEBUG(3,("More weirdness, could not open %s\n", 
  132.          slavedev));
  133.     return(False);
  134.   }
  135. #if defined(SVR4) || defined(SUNOS5) || defined(SCO) || defined(HPUX)
  136.   ioctl(slave, I_PUSH, "ptem");
  137.   ioctl(slave, I_PUSH, "ldterm");
  138. #else /* defined(SVR4) || defined(SUNOS5) || defined(SCO) || defined(HPUX) */
  139.   if (ioctl(slave,TIOCSCTTY,0) <0) {
  140.      DEBUG(3,("Error in ioctl call for slave pty\n"));
  141.      /* return(False); */
  142.   }
  143. #endif /* defined(SVR4) || defined(SUNOS5) || defined(SCO) || defined(HPUX) */
  144.  
  145.   /* Close master. */
  146.   close(master);
  147.  
  148.   /* Make slave stdin/out/err of child. */
  149.  
  150.   if (dup2(slave, STDIN_FILENO) != STDIN_FILENO) {
  151.     DEBUG(3,("Could not re-direct stdin\n"));
  152.     return(False);
  153.   }
  154.   if (dup2(slave, STDOUT_FILENO) != STDOUT_FILENO) {
  155.     DEBUG(3,("Could not re-direct stdout\n"));
  156.     return(False);
  157.   }
  158.   if (dup2(slave, STDERR_FILENO) != STDERR_FILENO) {
  159.     DEBUG(3,("Could not re-direct stderr\n"));
  160.     return(False);
  161.   }
  162.   if (slave > 2) close(slave);
  163.  
  164.   /* Set proper terminal attributes - no echo, canonical input processing,
  165.      no map NL to CR/NL on output. */
  166.  
  167.   if (tcgetattr(0, &stermios) < 0) {
  168.     DEBUG(3,("could not read default terminal attributes on pty\n"));
  169.     return(False);
  170.   }
  171.   stermios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
  172.   stermios.c_lflag |= ICANON;
  173.   stermios.c_oflag &= ~(ONLCR);
  174.   if (tcsetattr(0, TCSANOW, &stermios) < 0) {
  175.     DEBUG(3,("could not set attributes of pty\n"));
  176.     return(False);
  177.   }
  178.  
  179.   /* make us completely into the right uid */
  180.   if(!as_root) {
  181. #ifdef USE_SETRES
  182.     setresgid(0,0,0);
  183.     setresuid(0,0,0);
  184.     setresgid(gid,gid,gid);
  185.     setresuid(uid,uid,uid);      
  186. #else      
  187.     setuid(0);
  188.     seteuid(0);
  189.     setgid(gid);
  190.     setegid(gid);
  191.     setuid(uid);
  192.     seteuid(uid);
  193. #endif
  194.   }
  195.  
  196.   /* execl() password-change application */
  197.   if (execl("/bin/sh","sh","-c",passwordprogram,NULL) < 0) {
  198.     DEBUG(3,("Bad status returned from %s\n",passwordprogram));
  199.     return(False);
  200.   }
  201.   return(True);
  202. }
  203.  
  204. static int expect(int master,char *expected,char *buf)
  205. {
  206.   int n, m;
  207.  
  208.   n = 0;
  209.   buf[0] = 0;
  210.   while (1) {
  211.     if (n >= BUFSIZE-1) {
  212.       return False;
  213.     }
  214.  
  215.     /* allow 4 seconds for some output to appear */
  216.     m = read_with_timeout(master, buf+n, 1, BUFSIZE-1-n, 4000);
  217.     if (m < 0) 
  218.       return False;
  219.  
  220.     n += m;
  221.     buf[n] = 0;
  222.  
  223.     {
  224.       pstring s1,s2;
  225.       pstrcpy(s1,buf);
  226.       pstrcpy(s2,expected);
  227.       if (do_match(s1, s2, False))
  228.     return(True);
  229.     }
  230.   }
  231. }
  232.  
  233. static void pwd_sub(char *buf)
  234. {
  235.   string_sub(buf,"\\n","\n");
  236.   string_sub(buf,"\\r","\r");
  237.   string_sub(buf,"\\s"," ");
  238.   string_sub(buf,"\\t","\t");
  239. }
  240.  
  241. static void writestring(int fd,char *s)
  242. {
  243.   int l;
  244.   
  245.   l = strlen (s);
  246.   write (fd, s, l);
  247. }
  248.  
  249.  
  250. static int talktochild(int master, char *chatsequence)
  251. {
  252.   char buf[BUFSIZE];
  253.   int count=0;
  254.   char *ptr=chatsequence;
  255.   fstring chatbuf;
  256.  
  257.   *buf = 0;
  258.   sleep(1);
  259.  
  260.   while (next_token(&ptr,chatbuf,NULL)) {
  261.     BOOL ok=True;
  262.     count++;
  263.     pwd_sub(chatbuf);
  264.     if (!strequal(chatbuf,"."))
  265.       ok = expect(master,chatbuf,buf);
  266.  
  267.     if(lp_passwd_chat_debug())
  268.       DEBUG(100,("talktochild: chatbuf=[%s] responsebuf=[%s]\n",chatbuf,buf));
  269.  
  270.     if (!ok) {
  271.       DEBUG(3,("response %d incorrect\n",count));
  272.       return(False);
  273.     }
  274.  
  275.     if (!next_token(&ptr,chatbuf,NULL)) break;
  276.     pwd_sub(chatbuf);
  277.     if (!strequal(chatbuf,"."))
  278.       writestring(master,chatbuf);
  279.  
  280.     if(lp_passwd_chat_debug())
  281.       DEBUG(100,("talktochild: sendbuf=[%s]\n",chatbuf));
  282.   }
  283.  
  284.   if (count<1) return(False);
  285.  
  286.   return (True);
  287. }
  288.  
  289.  
  290. BOOL chat_with_program(char *passwordprogram,char *name,char *chatsequence, BOOL as_root)
  291. {
  292.   char *slavedev;
  293.   int master;
  294.   pid_t pid, wpid;
  295.   int wstat;
  296.   BOOL chstat;    
  297.  
  298.   /* allocate a pseudo-terminal device */
  299.   if ((master = findpty (&slavedev)) < 0) {
  300.     DEBUG(3,("Cannot Allocate pty for password change: %s",name));
  301.     return(False);
  302.   }
  303.  
  304.   if ((pid = fork()) < 0) {
  305.     DEBUG(3,("Cannot fork() child for password change: %s",name));
  306.     close(master);
  307.     return(False);
  308.   }
  309.  
  310.   /* we now have a pty */
  311.   if (pid > 0){            /* This is the parent process */
  312.     if ((chstat = talktochild(master, chatsequence)) == False) {
  313.       DEBUG(3,("Child failed to change password: %s\n",name));
  314.       kill(pid, SIGKILL); /* be sure to end this process */
  315.     }
  316.  
  317.     close(master);
  318.  
  319.     if ((wpid = sys_waitpid(pid, &wstat, 0)) < 0) {
  320.       DEBUG(3,("The process is no longer waiting!\n\n"));
  321.       return(False);
  322.     }
  323.     if (pid != wpid) {
  324.       DEBUG(3,("We were waiting for the wrong process ID\n"));    
  325.       return(False);
  326.     }
  327.     if (WIFEXITED(wstat) == 0) {
  328.       DEBUG(3,("The process exited while we were waiting\n"));
  329.       return(False);
  330.     }
  331.     if (WEXITSTATUS(wstat) != 0) {
  332.       DEBUG(3,("The status of the process exiting was %d\n", wstat));
  333.       return(False);
  334.     }
  335.     
  336.   } else {
  337.     /* CHILD */
  338.  
  339.     /* make sure it doesn't freeze */
  340.     alarm(20);
  341.  
  342.     if(as_root)
  343.       become_root(False);
  344.     DEBUG(3,("Dochild for user %s (uid=%d,gid=%d)\n",name,getuid(),getgid()));
  345.     chstat = dochild(master, slavedev, name, passwordprogram, as_root);
  346.  
  347.     if(as_root)
  348.       unbecome_root(False);
  349.   }
  350.   DEBUG(3,("Password change %ssuccessful for user %s\n", (chstat?"":"un"), name));
  351.   return (chstat);
  352. }
  353.  
  354.  
  355. BOOL chgpasswd(char *name,char *oldpass,char *newpass, BOOL as_root)
  356. {
  357.   pstring passwordprogram;
  358.   pstring chatsequence;
  359.   int i;
  360.   int len;
  361.  
  362.   strlower(name); 
  363.   DEBUG(3,("Password change for user: %s\n",name));
  364.  
  365. #if DEBUG_PASSWORD
  366.   DEBUG(100,("Passwords: old=%s new=%s\n",oldpass,newpass)); 
  367. #endif
  368.  
  369.   /* Take the passed information and test it for minimum criteria */
  370.   /* Minimum password length */
  371.   if (strlen(newpass) < MINPASSWDLENGTH) /* too short, must be at least MINPASSWDLENGTH */ 
  372.     {
  373.       DEBUG(2,("Password Change: %s, New password is shorter than MINPASSWDLENGTH\n",name));
  374.       return (False);        /* inform the user */
  375.     }
  376.   
  377.   /* Password is same as old password */
  378.   if (strcmp(oldpass,newpass) == 0) /* don't allow same password */
  379.     {
  380.       DEBUG(2,("Password Change: %s, New password is same as old\n",name)); /* log the attempt */
  381.       return (False);        /* inform the user */
  382.     }
  383.  
  384. #if (defined(PASSWD_PROGRAM) && defined(PASSWD_CHAT))
  385.   pstrcpy(passwordprogram,PASSWD_PROGRAM);
  386.   pstrcpy(chatsequence,PASSWD_CHAT);
  387. #else
  388.   pstrcpy(passwordprogram,lp_passwd_program());
  389.   pstrcpy(chatsequence,lp_passwd_chat());
  390. #endif
  391.  
  392.   if (!*chatsequence) {
  393.     DEBUG(2,("Null chat sequence - no password changing\n"));
  394.     return(False);
  395.   }
  396.  
  397.   if (!*passwordprogram) {
  398.     DEBUG(2,("Null password program - no password changing\n"));
  399.     return(False);
  400.   }
  401.  
  402.   /* 
  403.    * Check the old and new passwords don't contain any control
  404.    * characters.
  405.    */
  406.  
  407.   len = strlen(oldpass); 
  408.   for(i = 0; i < len; i++) {
  409.     if(iscntrl(oldpass[i])) {
  410.       DEBUG(0,("chat_with_program: oldpass contains control characters (disallowed).\n"));
  411.       return False;
  412.     }
  413.   }
  414.  
  415.   len = strlen(newpass);
  416.   for(i = 0; i < len; i++) {
  417.     if(iscntrl(newpass[i])) {
  418.       DEBUG(0,("chat_with_program: newpass contains control characters (disallowed).\n"));
  419.       return False;
  420.     }
  421.   }
  422.  
  423.   string_sub(passwordprogram,"%u",name);
  424.   string_sub(passwordprogram,"%o",oldpass);
  425.   string_sub(passwordprogram,"%n",newpass);
  426.  
  427.   string_sub(chatsequence,"%u",name);
  428.   string_sub(chatsequence,"%o",oldpass);
  429.   string_sub(chatsequence,"%n",newpass);
  430.   return(chat_with_program(passwordprogram,name,chatsequence, as_root));
  431. }
  432.  
  433. #else
  434. BOOL chgpasswd(char *name,char *oldpass,char *newpass, BOOL as_root)
  435. {
  436.   DEBUG(0,("Password changing not compiled in (user=%s)\n",name));
  437.   return(False);
  438. }
  439. #endif
  440.  
  441. /***********************************************************
  442.  Code to check the lanman hashed password.
  443. ************************************************************/
  444.  
  445. BOOL check_lanman_password(char *user, unsigned char *pass1, 
  446.                            unsigned char *pass2, struct smb_passwd **psmbpw)
  447. {
  448.   unsigned char unenc_new_pw[16];
  449.   unsigned char unenc_old_pw[16];
  450.   unsigned char null_pw[16];
  451.   struct smb_passwd *smbpw;
  452.  
  453.   *psmbpw = NULL;
  454.  
  455.   become_root(0);
  456.   smbpw = get_smbpwd_entry(user, 0);
  457.   unbecome_root(0);
  458.  
  459.   if(smbpw == NULL)
  460.   {
  461.     DEBUG(0,("check_lanman_password: get_smbpwd_entry returned NULL\n"));
  462.     return False;
  463.   }
  464.  
  465.   if(smbpw->acct_ctrl & ACB_DISABLED)
  466.   {
  467.     DEBUG(0,("check_lanman_password: account %s disabled.\n", user));
  468.     return False;
  469.   }
  470.  
  471.   if((smbpw->smb_passwd == NULL) && (smbpw->acct_ctrl & ACB_PWNOTREQ))
  472.   {
  473.     unsigned char no_pw[14];
  474.     memset(no_pw, '\0', 14);
  475.     E_P16((uchar *)no_pw, (uchar *)null_pw);
  476.     smbpw->smb_passwd = null_pw;
  477.   } else if (smbpw->smb_passwd == NULL) {
  478.     DEBUG(0,("check_lanman_password: no lanman password !\n"));
  479.     return False;
  480.   }
  481.  
  482.   /* Get the new lanman hash. */
  483.   D_P16(smbpw->smb_passwd, pass2, unenc_new_pw);
  484.  
  485.   /* Use this to get the old lanman hash. */
  486.   D_P16(unenc_new_pw, pass1, unenc_old_pw);
  487.  
  488.   /* Check that the two old passwords match. */
  489.   if(memcmp(smbpw->smb_passwd, unenc_old_pw, 16))
  490.   {
  491.     DEBUG(0,("check_lanman_password: old password doesn't match.\n"));
  492.     return False;
  493.   }
  494.  
  495.   *psmbpw = smbpw;
  496.   return True;
  497. }
  498.  
  499. /***********************************************************
  500.  Code to change the lanman hashed password.
  501.  It nulls out the NT hashed password as it will
  502.  no longer be valid.
  503. ************************************************************/
  504.  
  505. BOOL change_lanman_password(struct smb_passwd *smbpw, unsigned char *pass1, unsigned char *pass2)
  506. {
  507.   unsigned char unenc_new_pw[16];
  508.   unsigned char null_pw[16];
  509.   BOOL ret;
  510.  
  511.   if(smbpw == NULL)
  512.   { 
  513.     DEBUG(0,("change_lanman_password: get_smbpwd_entry returned NULL\n"));
  514.     return False;
  515.   }
  516.  
  517.   if(smbpw->acct_ctrl & ACB_DISABLED)
  518.   {
  519.     DEBUG(0,("change_lanman_password: account %s disabled.\n", smbpw->smb_name));
  520.     return False;
  521.   }
  522.  
  523.   if((smbpw->smb_passwd == NULL) && (smbpw->acct_ctrl & ACB_PWNOTREQ))
  524.   {
  525.     unsigned char no_pw[14];
  526.     memset(no_pw, '\0', 14);
  527.     E_P16((uchar *)no_pw, (uchar *)null_pw);
  528.     smbpw->smb_passwd = null_pw;
  529.   } else if (smbpw->smb_passwd == NULL) {
  530.     DEBUG(0,("change_lanman_password: no lanman password !\n"));
  531.     return False;
  532.   }
  533.  
  534.   /* Get the new lanman hash. */
  535.   D_P16(smbpw->smb_passwd, pass2, unenc_new_pw);
  536.  
  537.   smbpw->smb_passwd = unenc_new_pw;
  538.   smbpw->smb_nt_passwd = NULL; /* We lose the NT hash. Sorry. */
  539.  
  540.   /* Now write it into the file. */
  541.   become_root(0);
  542.   ret = mod_smbpwd_entry(smbpw, False);
  543.   unbecome_root(0);
  544.     
  545.   return ret;
  546. }
  547.  
  548. /***********************************************************
  549.  Code to check the OEM hashed password.
  550. ************************************************************/
  551.  
  552. BOOL check_oem_password(char *user, unsigned char *data,
  553.                         struct smb_passwd **psmbpw, char *new_passwd,
  554.                         int new_passwd_size)
  555. {
  556.   struct smb_passwd *smbpw = NULL;
  557.   int new_pw_len;
  558.   fstring upper_case_new_passwd;
  559.   unsigned char new_p16[16];
  560.   unsigned char unenc_old_pw[16];
  561.   unsigned char null_pw[16];
  562.  
  563.   become_root(0);
  564.   *psmbpw = smbpw = get_smbpwd_entry(user, 0);
  565.   unbecome_root(0);
  566.  
  567.   if(smbpw == NULL)
  568.   {
  569.     DEBUG(0,("check_oem_password: get_smbpwd_entry returned NULL\n"));
  570.     return False;
  571.   }
  572.  
  573.   if(smbpw->acct_ctrl & ACB_DISABLED)
  574.   {
  575.     DEBUG(0,("check_lanman_password: account %s disabled.\n", user));
  576.     return False;
  577.   }
  578.  
  579.   if((smbpw->smb_passwd == NULL) && (smbpw->acct_ctrl & ACB_PWNOTREQ))
  580.   {
  581.     unsigned char no_pw[14];
  582.     memset(no_pw, '\0', 14);
  583.     E_P16((uchar *)no_pw, (uchar *)null_pw);
  584.     smbpw->smb_passwd = null_pw;
  585.   } else if (smbpw->smb_passwd == NULL) {
  586.     DEBUG(0,("check_oem_password: no lanman password !\n"));
  587.     return False;
  588.   }
  589.  
  590.   /* 
  591.    * Call the hash function to get the new password.
  592.    */
  593.   SamOEMhash( (unsigned char *)data, (unsigned char *)smbpw->smb_passwd, True);
  594.  
  595.   /* 
  596.    * The length of the new password is in the last 4 bytes of
  597.    * the data buffer.
  598.    */
  599.   new_pw_len = IVAL(data,512);
  600.   if(new_pw_len < 0 || new_pw_len > new_passwd_size - 1) {
  601.     DEBUG(0,("check_oem_password: incorrect password length (%d).\n", new_pw_len));
  602.     return False;
  603.   }
  604.  
  605.   memcpy(new_passwd, &data[512-new_pw_len], new_pw_len);
  606.   new_passwd[new_pw_len] = '\0';
  607.  
  608.   /*
  609.    * To ensure we got the correct new password, hash it and
  610.    * use it as a key to test the passed old password.
  611.    */
  612.  
  613.   memset(upper_case_new_passwd, '\0', sizeof(upper_case_new_passwd));
  614.   fstrcpy(upper_case_new_passwd, new_passwd);
  615.   strupper(upper_case_new_passwd);
  616.  
  617.   E_P16((uchar *)upper_case_new_passwd, new_p16);
  618.  
  619.   /*
  620.    * Now use new_p16 as the key to see if the old
  621.    * password matches.
  622.    */
  623.   D_P16(new_p16, &data[516], unenc_old_pw);
  624.  
  625.   if(memcmp(smbpw->smb_passwd, unenc_old_pw, 16)) {
  626.     DEBUG(0,("check_oem_password: old password doesn't match.\n"));
  627.     return False;
  628.   }
  629.  
  630.   memset(upper_case_new_passwd, '\0', strlen(upper_case_new_passwd));
  631.  
  632.   return True;
  633. }
  634.  
  635. /***********************************************************
  636.  Code to change the oem password. Changes both the lanman
  637.  and NT hashes.
  638.  override = False, normal
  639.  override = True, override XXXXXXXXXX'd password
  640. ************************************************************/
  641.  
  642. BOOL change_oem_password(struct smb_passwd *smbpw, char *new_passwd, BOOL override)
  643. {
  644.   int ret;
  645.   fstring upper_case_new_passwd;
  646.   unsigned char new_nt_p16[16];
  647.   unsigned char new_p16[16];
  648.  
  649.   memset(upper_case_new_passwd, '\0', sizeof(upper_case_new_passwd));
  650.   fstrcpy(upper_case_new_passwd, new_passwd);
  651.   strupper(upper_case_new_passwd);
  652.  
  653.   E_P16((uchar *)upper_case_new_passwd, new_p16);
  654.  
  655.   smbpw->smb_passwd = new_p16;
  656.   
  657.   E_md4hash((uchar *) new_passwd, new_nt_p16);
  658.   smbpw->smb_nt_passwd = new_nt_p16;
  659.   
  660.   /* Now write it into the file. */
  661.   become_root(0);
  662.   ret = mod_smbpwd_entry(smbpw, override);
  663.   unbecome_root(0);
  664.  
  665.   memset(upper_case_new_passwd, '\0', strlen(upper_case_new_passwd));
  666.   memset(new_passwd, '\0', strlen(new_passwd));
  667.  
  668.   return ret;
  669. }
  670.